<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

use app\middleware\AuthMiddleware;
use app\middleware\ClientMiddleware;
use think\facade\Route;

Route::get('/', function () {
    return 'api';
});
Route::group(function () {
    Route::group('auth', function () {
        Route::post('register', 'Auth/register');
        Route::post('login', 'Auth/login');
        Route::post('refresh', 'Auth/refreshToken');
        Route::post('sms/send', 'Auth/sendSmsCode');
        Route::get('partial/status', 'Auth/getPartialStatus');
        Route::group('verification', function () {
            Route::get('company', 'Auth/getCompanyVerification');
            Route::post('company', 'Auth/saveCompanyVerification');
            Route::get('qiniu', 'Auth/qiniuPartial');
            Route::post('license-ocr', 'Auth/recognizeCompanyLicense');
            Route::post('invoice', 'Auth/saveCompanyInvoice');
            Route::post('addresses', 'Auth/saveCompanyAddresses');
            Route::get('regions', 'Auth/getVerificationRegions');
            Route::get('geo-regions', 'Auth/getGeoRegions');
        });
    });
    Route::group(function () {
        Route::group('auth', function () {
            Route::post('logout', 'Auth/logout');
            Route::get('menus', 'Auth/menus');
            Route::get('qiniu', 'Auth/qiniu');
        });
        Route::group('user', function () {
            Route::get('profile', 'user.Profile/show');
            Route::put('profile', 'user.Profile/update');
            Route::put('profile/password', 'user.Profile/updatePassword');
            Route::put('org/:id/settings', 'user.Profile/updateOrg');
            Route::group('notify', function () {
                Route::get('summary', 'user.Notification/summary');
                Route::get('personal', 'user.Notification/personal');
                Route::get('group', 'user.Notification/group');
                Route::get('all', 'user.Notification/all');
                Route::post('read', 'user.Notification/markRead');
            });
        });
        Route::group('system', function () {
            Route::resource('config', 'system.Config')
                ->only(['index', 'read', 'save', 'update', 'delete']);

            Route::resource('menu', 'system.Menu')
                ->except(['read', 'create', 'edit']);

            Route::resource('account', 'system.Account')
                ->except(['create', 'edit']);

            Route::resource('role', 'system.Role')
                ->except(['create', 'edit']);

            Route::resource('permission', 'system.Permission')
                ->except(['create', 'edit']);

            Route::group('org', function () {
                Route::resource('organizations', 'system.org.Organization')
                    ->except(['create', 'edit']);
                Route::resource('members', 'system.org.Member')
                    ->except(['create', 'edit']);
                Route::post('audit/fast-create', 'system.OrgAudit/fastCreate');
                Route::get('audit', 'system.OrgAudit/index');
                Route::post('audit/:userId/approve', 'system.OrgAudit/approve');
                Route::post('audit/:userId/reject', 'system.OrgAudit/reject');
            });

            Route::group('region', function () {
                Route::resource('regions', 'system.region.Region')
                    ->except(['create', 'edit']);
                Route::resource('users', 'system.region.User')
                    ->except(['create', 'edit']);
            });

            Route::group('verify', function () {
                Route::resource('stock', 'system.verify.Stock')
                    ->only(['index', 'read', 'update']);
                Route::resource('inquiry', 'system.verify.Inquiry')
                    ->only(['index', 'read', 'update']);
            });

            Route::group('product', function () {
                Route::resource('category', 'system.product.Category')
                    ->except(['create', 'edit']);
                Route::resource('brand', 'system.product.Brand')
                    ->except(['create', 'edit']);
                Route::post('item/bulk-upload', 'system.product.Prod/bulkUpload');
                Route::resource('item', 'system.product.Prod')
                    ->except(['create', 'edit']);
                Route::resource('import-job', 'system.product.ImportJob')
                    ->only(['index', 'read']);
            });

            Route::group('order', function () {
                Route::resource('orders', 'system.order.Order')
                    ->except(['create', 'edit']);
                Route::resource('shipments', 'system.order.Shipment')
                    ->except(['create', 'edit']);
                Route::resource('pickup', 'system.order.Pickup')
                    ->only(['index', 'read', 'update']);
                Route::resource('refund', 'system.order.Refund')
                    ->only(['index', 'read']);
                Route::resource('ship-company', 'system.order.ShipmentCompany')
                    ->except(['create', 'edit']);
            });

            Route::group('settlement', function () {
                Route::resource('statement', 'system.settlement.Statement')
                    ->except(['create', 'edit', 'delete']);
                Route::resource('invoice', 'system.settlement.Invoice')
                    ->except(['create', 'edit', 'delete']);
                Route::resource('payout', 'system.settlement.Payout')
                    ->except(['create', 'edit', 'delete']);
            });

            Route::group('notify', function () {
                Route::resource('template', 'system.notify.Template')
                    ->except(['create', 'edit']);
                Route::resource('record', 'system.notify.Record')
                    ->only(['index', 'read']);
                Route::post('record/:id/read', 'system.notify.Record/markRead');
                Route::post('record/:id/resend', 'system.notify.Record/resend');
                Route::resource('message', 'system.notify.Message')
                    ->only(['save']);
            });
        });
        Route::group('seller', function () {
            Route::group('verify', function () {
                Route::resource('stock', 'seller.verify.Stock')
                    ->only(['index', 'read', 'update']);
                Route::resource('inquiry', 'seller.verify.Inquiry')
                    ->only(['index', 'read', 'update']);
            });
            Route::group('trade', function () {
                Route::resource('order', 'trade.Order')
                    ->only(['index', 'read']);
            });
        });
        Route::group('buyer', function () {
            Route::group('verify', function () {
                Route::resource('stock', 'buyer.verify.Stock')
                    ->only(['index', 'read', 'save', 'delete']);
                Route::resource('inquiry', 'buyer.verify.Inquiry')
                    ->only(['index', 'read', 'save', 'delete']);
            });
        });
        Route::group('trade', function () {
            Route::resource('order', 'trade.Order')
                ->only(['index', 'read']);

            Route::resource('cart', 'trade.Cart')
                ->only(['index', 'save', 'update', 'delete']);
            Route::post('cart/:id/spotcheck', 'trade.Cart/spotCheck');

            Route::resource('after-sale', 'trade.AfterSale')
                ->only(['index', 'read', 'save', 'update']);
        });
    })->middleware(AuthMiddleware::class);
})->middleware(ClientMiddleware::class);
